package com.ruoyi.business.controller;

import com.ruoyi.business.domain.Depart;
import com.ruoyi.business.domain.Staff;
import com.ruoyi.business.service.IDepartService;
import com.ruoyi.business.service.IStaffService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 *
 * @author win
 * @date 2021-06-14
 */
@RestController
@RequestMapping("/Staff/staff")
public class StaffController extends BaseController
{
    @Autowired
    private IDepartService departService;

    @Autowired
    private IStaffService staffService;

    /**
     *
     */
//    @PreAuthorize("@ss.hasPermi('business:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(Staff staff)
    {
        startPage();
        List<Staff> list = staffService.selectStaffList(staff);
        return getDataTable(list);
    }

    /**
     *
     */
//    @PreAuthorize("@ss.hasPermi('business:content:export')")
    @Log(title = "Staff", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Staff staff)
    {
        List<Staff> list = staffService.selectStaffList(staff);
        ExcelUtil<Staff> util = new ExcelUtil<Staff>(Staff.class);
        return util.exportExcel(list, "Staff数据");
    }

    /**
     *
     */
//    @PreAuthorize("@ss.hasPermi('business:content:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(staffService.selectStaffById(id));
    }

    /**
     *
     */
//    @PreAuthorize("@ss.hasPermi('business:content:add')")
    @Log(title = "Staff", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Staff staff)
    {
        return toAjax(staffService.insertStaff(staff));
    }

    /**
     *
     */
//    @PreAuthorize("@ss.hasPermi('business:content:edit')")
    @Log(title = "Staff", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Staff staff)
    {
        return toAjax(staffService.updateStaff(staff));
    }

    /**
     *
     */
//    @PreAuthorize("@ss.hasPermi('business:content:remove')")
    @Log(title = "Staff", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(staffService.deleteStaffByIds(ids));
    }
}
